package com.lian.aieduc.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.metrics.buffering.StartupTimeline;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {

    private Integer code;
    private String message;
    private T data;

    /**
     * 成功的结果响应 不带参数
     * @return
     * @param <T>
     */
    public static <T> Result<T> success() {
        return new Result<>(0, "success", null);
    }

        public static <T> Result<T> success(String message,T data) {
            return new Result<>(0, message, data);
        }

    /**
     * 成功的结果响应
     * @param data 响应数据
     * @return
     * @param <T>
     */
    public static <T> Result<T> success(T data) {
        return new Result<>(0, "success", data);
    }

    public static <T> Result<T> failure( String message) {
        return new Result<>(1, message, null);
    }

    /**
     * 错误的结果响应
     * @param code 状态码
     * @param message 错误消息
     * @return
     * @param <T>
     */
    public static <T> Result<T> failure(Integer code, String message) {
        return new Result<>(code, message, null);
    }

    /**
     * 错误的结果响应
     * @param code 状态码
     * @param message 错误消息
     * @param data 错误数据
     * @return
     * @param <T>
     */
    public static <T> Result<T> failure(Integer code, String message, T data) {
        return new Result<>(code, message, data);
    }

}
